package com.hshe.springmvcdemo.interceptors;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import javax.annotation.Resource;

/**
 * @author h
 * @since 2019-12-20 18 14
 * <p>
 * springmvc静态资源放行。
 * 拦截器
 */
@Configuration
public class MvcConfig extends WebMvcConfigurationSupport {

    @Resource
    private LogsInterceptor logsInterceptor;


    /**
     * 拦截规则
     *
     * @param registry
     */
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(logsInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/", "/author", "/error");
        super.addInterceptors(registry);
    }


    /**
     * 静态资源放行。
     *
     * @param registry
     */
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/");
        super.addResourceHandlers(registry);
    }
}
